package com.chunguang.netty.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chunguang.netty.domain.RequestData;
import com.chunguang.netty.domain.RequestDataExample;
import com.chunguang.netty.domain.TransferData;
import com.chunguang.netty.domain.TransferDataExample;
import com.chunguang.netty.mapper.RequestDataMapper;
import com.chunguang.netty.mapper.TransferDataMapper;
import com.chunguang.netty.service.RequestDataService;

@Service(value="requestDataService")
public class RequestDataServiceImpl implements RequestDataService{

	@Autowired
	private RequestDataMapper dataMapper;
	@Autowired
	private TransferDataMapper transferDataMapper;
	
	@Override
	public boolean exist(String checkNumber) {
	 
		RequestDataExample example = new RequestDataExample() ;
		example.createCriteria().andCheckNumberEqualTo(checkNumber);
		List<RequestData> data = dataMapper.selectByExample(example );
		if (data!=null && data.size()>0) {
			return true;
		}
		return false;
	}

	@Override
	public void insert(RequestData requestData) {
	 
		dataMapper.insert(requestData);
	}

	@Override
	public void update(RequestData requestData) {
		RequestDataExample example = new RequestDataExample() ;
		example.createCriteria().andCheckNumberEqualTo(requestData.getCheckNumber());
		dataMapper.updateByExample(requestData, example);
	}
	@Override
	public void update(TransferData requestData) {
		TransferDataExample example = new TransferDataExample() ;
		example.createCriteria().andCheckNumberEqualTo(requestData.getCheckNumber());
		transferDataMapper.updateByExample(requestData, example);
	}

	@Override
	public void updateSync(String data) {
		TransferData select = select(data);
		
		select.setSync(1);
		update(select);
		
	}

	@Override
	public TransferData select(String checkNumber) {
		TransferDataExample example = new TransferDataExample() ;
		example.createCriteria().andCheckNumberEqualTo(checkNumber);
		List<TransferData> data = transferDataMapper.selectByExample(example );
		if (data!=null && data.size()>0) {
			return data.get(0);
		}
		return null;
	}

	@Override
	public void insert(TransferData requestData) {
		// TODO Auto-generated method stub
		transferDataMapper.insert(requestData);
	}

}
